<template>
	<view>
		<cu-custom bgColor="bg-gradual-orange" :isBack="true">
			<block slot="content">商家签约二维码</block>
		</cu-custom>
		<view class="qrcode">
			<image :src="sign_url" @click="previewImage"></image>
		</view>
	</view>
</template>

<script>
	import {
		mapState,
		mapMutations
	} from 'vuex';
	import merchant from '@/api/merchant'
	export default {
		data() {
			return {
				sign_url: '',
				id: 0,
			}
		},
		onLoad(opts) {
			this.id = opts.id
			this.review()
			this.getDetail()
		},
		methods: {
			previewImage(url) {
				uni.previewImage({
					urls: [url], // 需要预览的图片链接列表
					current: url, // 当前显示的图片链接
					success: res => {
						console.log('previewImage success', res);
					},
					fail: err => {
						console.error('previewImage fail', err);
					}
				});
			},
			review() {
				merchant.review({
					id: this.id
				}).then(res => {
					uni.showToast({
						title: res.msg,
						icon: 'none'
					})
				})
			},
			getDetail(id) {
				merchant.sign_url().then(res => {
					if (res.code === 1) {
						this.sign_url = res.data;
					} else {
						uni.showToast({
							title: res.msg,
							icon: 'none'
						})
					}
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.qrcode {
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		margin-top: 40%;

		.text {
			margin-bottom: 20px;
			font-size: 20px;
		}

		image {
			width: 300px;
			height: 300px;
		}
	}
</style>